<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <!-- <script type="text/javascript" src="http://static.runoob.com/assets/jquery/2.0.3/jquery.min.js"></script> -->
  <script type="text/javascript" src="./qrcode.min.js"></script>
  <!-- <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.9.359/pdf.min.js"></script>
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.9.359/pdf.worker.min.js"></script> -->
  <!-- <script charset="utf-8" src="https://map.qq.com/api/gljs?v=1.exp&libraries=service&key=ACQBZ-XKA3X-MVE43-ZFW6Q-KPWN2-KSBTR"></script> -->
  <title>Vite App</title>
  <script type="text/javascript">
    (function () {
      if (window.zhuge) return;
      window.zhuge = [];
      window.zhuge.methods = "_init identify track trackRevenue getDid getSid getKey setSuperProperty setUserProperties setWxProperties setPlatform".split(" ");
      window.zhuge.factory = function (b) {
        return function () {
          var a = Array.prototype.slice.call(arguments);
          a.unshift(b);
          window.zhuge.push(a);
          return window.zhuge;
        }
      };
      for (var i = 0; i < window.zhuge.methods.length; i++) {
        var key = window.zhuge.methods[i];
        window.zhuge[key] = window.zhuge.factory(key);
      }
      window.zhuge.load = function (b, x) {
        if (!document.getElementById("zhuge-js")) {
          var a = document.createElement("script");
          var verDate = new Date();
          var verStr = verDate.getFullYear().toString() + verDate.getMonth().toString() + verDate.getDate().toString();

          a.type = "text/javascript";
          a.id = "zhuge-js";
          a.async = !0;
          a.src = 'https://su.zhugeio.com/zhuge.js?v=' + verStr;
          a.onerror = function () {
            window.zhuge.identify = window.zhuge.track = function (ename, props, callback) {
              if (callback && Object.prototype.toString.call(callback) === '[object Function]') {
                callback();
              } else if (Object.prototype.toString.call(props) === '[object Function]') {
                props();
              }
            };
          };
          var c = document.getElementsByTagName("script")[0];
          c.parentNode.insertBefore(a, c);
          window.zhuge._init(b, x)
        }
      };
      window.zhuge.load('3159e657d82c4392b0b411df53b30f4f', { //配置应用的AppKey
        superProperty: { //全局的事件属性(选填)
          '应用名称': '数据分析'
        },
        adTrack: false,//广告监测开关，默认为false
        zgsee: false,//视屏采集开关， 默认为false
        autoTrack: false,
        //启用全埋点采集（选填，默认false）
        singlePage: false //是否是单页面应用（SPA），启用autoTrack后生效（选填，默认false）
      });
    })();
  </script>
</head>

<body>
  <div id="root"></div>
  <div id="map"></div>
  <script type="module" src="/src/main.tsx"></script>
  <script src="./wasm_exec.js"></script>
  <script>
    // // rust实现webAssembly
    // const importObject = {
    //   env: {
    //     // 空实现mem和table,分别为内存和表格的占位符
    //     mem: new WebAssembly.Memory({ initial: 1 }),
    //     table: new WebAssembly.Table({ initial: 1, element: "anyfunc" }),
    //   },
    // };
    // // 使用fetch从服务器上获取wasm二进制数据
    // fetch("./wasm/target/wasm32-unknown-unknown/release/wasm.wasm")
    //   .then((response) => response.arrayBuffer())
    //   .then((bytes) => WebAssembly.instantiate(bytes, importObject))
    //   .then((results) => {
    //     const add = results.instance.exports.add;
    //     console.log(add(1, 2)); // 输出3
    //   });

    // go实现webAssembly
    const go = new Go(); // Defined in wasm_exec.js
    const WASM_URL = "wasm.wasm";
    var wasm;
    go.importObject.env = {
      add: function (x, y) {
        // 设置go代码执行环境中的方法
        return x + y;
      },
    };

    if ("instantiateStreaming" in WebAssembly) {
      WebAssembly.instantiateStreaming(fetch(WASM_URL), go.importObject).then(
        function (obj) {
          wasm = obj.instance;
          console.log(wasm.exports, wasm.exports.multiply(2, 4)); // 执行go中暴露的方法
          go.run(wasm); // 执行go函数中的main方法
        }
      );
    } else {
      fetch(WASM_URL)
        .then((resp) => resp.arrayBuffer())
        .then((bytes) =>
          WebAssembly.instantiate(bytes, go.importObject).then(function (
            obj
          ) {
            wasm = obj.instance;
            go.run(wasm);
          })
        );
    }
  </script>
</body>

</html>